package cn.edu.ecnu.gis.client.liwamap;

import cn.edu.ecnu.gis.client.model.Gadget;
import cn.edu.ecnu.gis.client.model.GadgetClass;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ImageBundle;
import com.google.gwt.user.client.ui.MouseListener;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

import org.gwtsvg.client.Coordinate;
import org.gwtsvg.client.SVGPanel;
import org.gwtsvg.client.basicshapes.Line;

public class LiwaMapGadget extends Gadget implements MouseListener {

    // private HTML divForLiwaMap = new HTML("<div id='liwamap ' style='height:300'></div>");
    private VerticalPanel vPanel = new VerticalPanel();
    private SVGPanel sVGPanel = new SVGPanel(300, 300);
    private Line line;
    public Coordinate origin;
    public Coordinate passway;
    public Coordinate end;

    public static class Class extends GadgetClass {

        public Class() {
            super("SVG地图", false);
            this.setGadgetType(1);
        }

        public Gadget newGadget() {
            return new LiwaMapGadget(this);
        }
    }

    protected LiwaMapGadget(Class c) {
        super(c);
        initWidget(vPanel);
        SVGPanel sVGPanel = new SVGPanel(300, 300);
        Button b = new Button("hello");
        vPanel.add(b);
        vPanel.setStyleName("svgPanel");

        vPanel.add(sVGPanel);
        //  flowPanel.setStyleName("googlemap");
        //map.setCenter(31.22, 121.48);
        sVGPanel.addMouseListener(this);
    }

    public void onMouseDown(Widget arg0, int arg1, int arg2) {
        origin = new Coordinate(arg1, arg2);
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void onMouseEnter(Widget arg0) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void onMouseLeave(Widget arg0) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void onMouseMove(Widget arg0, int arg1, int arg2) {
        sVGPanel.remove(line);
        passway = new Coordinate(arg1, arg2);
        line = new Line(origin, passway);
        sVGPanel.add(line);

    }

    public void onMouseUp(Widget arg0, int arg1, int arg2) {
        line = new Line(origin, passway);
        sVGPanel.add(line);

    }

    public AbstractImagePrototype getBoundImage() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
